package com.learn.common.utils;


import com.learn.common.enums.ResultEnum;
import com.learn.common.utils.result.CommonResult;

public class ResultUtil<T> {

    /**
     * 返回成功结果及数据
     *
     * @param resultEnum
     * @return
     */
    public CommonResult<T> succ(ResultEnum resultEnum, T t) {
        CommonResult<T> result = new CommonResult(resultEnum.getMsg(),resultEnum.getState(),t);
        return result;
    }

    /** 返回成功结果及数据
     *
     * @param resultEnum
     * @param object
     * @return
     */
    public static CommonResult<Object> success(ResultEnum resultEnum, Object object) {
        CommonResult<Object> result = new CommonResult(resultEnum.getMsg(),resultEnum.getState(),object);
        return result;
    }

    /**
     * 返回成功结果
     *
     * @param resultEnum
     * @return
     */
    public static CommonResult<Object> success(ResultEnum resultEnum) {
        return success(resultEnum, null);
    }

    /**
     * 返回自定义成功结果
     *
     * @param state
     * @param msg
     * @return
     */
    public static CommonResult<Object> success(Integer state, String msg, Object object) {
        CommonResult<Object> result = new CommonResult<Object>(msg,state,object);
        return result;
    }

    /**
     * 返回自定义异常结果
     *
     * @param state
     * @param msg
     * @return
     */
    public static CommonResult<Object> error(Integer state, String msg) {
        CommonResult<Object> result = new CommonResult<Object>(msg,state,null);
        return result;
    }


    /**
     * 返回失败结果
     *
     * @param resultEnum
     * @return
     */
    public CommonResult<T> err(ResultEnum resultEnum) {
        CommonResult<T> result = new CommonResult<>(resultEnum.getMsg(),resultEnum.getState(), null);
        return result;
    }

    /**
     * 返回失败结果
     *
     * @param resultEnum
     * @return
     */
    public static CommonResult<Object> error(ResultEnum resultEnum) {
        CommonResult<Object> result = new CommonResult<Object>(resultEnum.getMsg(),resultEnum.getState(), null);
        return result;
    }

}
